#include "comm.hpp"
int main()
{
    //获取共享内存
    int shmid = GetShm();

    int fd = open("mkfifo", O_WRONLY, 0666);
    if(fd == -1)
    {
        perror("mkfifo open");
        exit(MKFIFO_OPEN_ERR);
    }

    //挂接到进程
    char* shmaddr = (char*)shmat(shmid, nullptr, 0);

    //通信
    //没有控制好
    // while(true)
    // {
    //     cout << "pelase@";
    //     char wbuffer[1024] = {'\0'};
    //     fgets(wbuffer, sizeof(wbuffer), stdin);
    //     write(fd, wbuffer, strlen(wbuffer));
    //     fgets(shmaddr, sizeof(shmaddr), stdin);
    //     sleep(1);
    // }

    while(true)
    {
        cout << "please@";
        fgets(shmaddr, sizeof(shmaddr), stdin);
        char c;
        write(fd, &c, 1);
    }

    //去关联
    shmdt(shmaddr);
    return 0;
}